home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / netBoot / xxboot.c < prev   
Encoding:
C/C++ Source or Header  |  1988-05-13  |  3.0 KB  |  152 lines

  1.  
  2. /*
  3.  * @(#)xxboot.c 1.1 86/09/27
  4.  * Copyright (c) 1986 by Sun Microsystems, Inc.
  5.  */
  6.  
  7. /*
  8.  * General boot code for routines which implement the "standalone
  9.  * driver" boot interface.
  10.  */
  11.  
  12. #include "saio.h"
  13. #include "bootparam.h"
  14. #include "sunromvec.h"
  15.  
  16. extern char *devalloc();
  17. extern char *resalloc();
  18. extern int tftpboot();
  19.  
  20. int
  21. xxboot(bp)
  22.     register struct bootparam *bp;
  23. {
  24.     struct saioreq req;
  25.     int blkno;
  26.     char *addr;
  27.  
  28.     req.si_ctlr = bp->bp_ctlr;
  29.     req.si_unit = bp->bp_unit;
  30.     req.si_boff = (daddr_t)bp->bp_part;
  31.     req.si_boottab = bp->bp_boottab;
  32.  
  33.     if (devopen(&req))    /* Do all the hard work */
  34.         return -1;
  35.  
  36.     for (blkno = 1, addr = (char *)LOADADDR;
  37.          blkno <= BBSIZE/DEV_BSIZE;
  38.          blkno++, addr += DEV_BSIZE) {
  39.         req.si_bn = blkno;
  40.         req.si_cc = DEV_BSIZE;
  41.         req.si_ma = addr;
  42.         if (req.si_cc != (*bp->bp_boottab->b_strategy)(&req, READ))
  43.             return -1;
  44.     }
  45.     return LOADADDR;
  46. }
  47.  
  48. int
  49. devopen(sip)
  50.     register struct saioreq *sip;
  51. {
  52.     register struct devinfo *dp;
  53.     char *a;
  54.  
  55.     sip->si_devaddr = sip->si_devdata = sip->si_dmaaddr = (char *)0;
  56.     dp = sip->si_boottab->b_devinfo;
  57.     if (dp) {
  58.         /* Map controller number into controller address */
  59.         if (sip->si_ctlr < dp->d_stdcount) {
  60.             sip->si_ctlr = (int)((dp->d_stdaddrs)[sip->si_ctlr]);
  61.         }
  62.         /* Map in device itself */
  63.         if (dp->d_devbytes) {
  64.             a = devalloc(dp->d_devtype, sip->si_ctlr,
  65.                 dp->d_devbytes);
  66.             if (!a)
  67.                 return (-1);
  68.             sip->si_devaddr = a;
  69.         }
  70.         if (dp->d_dmabytes) {
  71.             a = resalloc(RES_DMAMEM, dp->d_dmabytes);
  72.             if (!a) 
  73.                 return (-1);
  74.             sip->si_dmaaddr = a;
  75.         }
  76.         if (dp->d_localbytes) {
  77.             a = resalloc(RES_MAINMEM, dp->d_localbytes);
  78.             if (!a) 
  79.                 return (-1);
  80.             sip->si_devdata = a;
  81.         }
  82.     }
  83.     return ((sip->si_boottab->b_open)(sip));
  84. }
  85.  
  86. /*
  87.  * Close device, release resources.
  88.  * FIXME, prom HAS no resources!!!
  89.  */
  90. int
  91. devclose(sip)
  92.     struct saioreq *sip;
  93. {
  94.     return ((*sip->si_boottab->b_close)(sip));
  95. }
  96.  
  97. int
  98. ttboot(bp)
  99.         register struct bootparam *bp;
  100. {
  101.         struct saioreq req;
  102.         int blkno;
  103.     register int len;
  104.         char *addr;
  105.     register int result = -1;
  106.  
  107.         req.si_ctlr = bp->bp_ctlr;
  108.         req.si_unit = bp->bp_unit;
  109.         req.si_boff = (daddr_t)bp->bp_part;
  110.     req.si_boottab = bp->bp_boottab;
  111.  
  112.         if (devopen(&req))      /* Do all the hard work */
  113.                 return -1;
  114.  
  115.         for (blkno = 1, addr = (char *)LOADADDR;; blkno++, addr += len) {
  116.                 req.si_bn = blkno;
  117.                 req.si_cc = 32768;
  118.                 req.si_ma = addr;
  119.         len = (*bp->bp_boottab->b_strategy)(&req, READ);
  120.         if (len == 0) {
  121.             if (blkno != 1)
  122.                 result = LOADADDR;
  123.             break;
  124.         }
  125.         }
  126.     (*bp->bp_boottab->b_close)(&req);
  127.         return result;
  128. }
  129.  
  130. int
  131. tftpboot(bp)
  132.         register struct bootparam *bp;
  133. {
  134.         struct saioreq req;
  135.         int blkno;
  136.         char *addr;
  137.  
  138.         req.si_ctlr = bp->bp_ctlr;
  139.         req.si_unit = bp->bp_unit;
  140.         req.si_boff = (daddr_t)bp->bp_part;
  141.         req.si_boottab = bp->bp_boottab;
  142.  
  143.         if (devopen(&req))      /* Do all the hard work */
  144.                 return -1;
  145.  
  146.     if (tftpload(&req) == -1){
  147.         return(-1);
  148.     } else {
  149.         return LOADADDR;
  150.     }
  151. }
  152.